function [sum] = templateMatching(img, templateimg)
%This function makes a template matching
%We experimant with it, but don't use it
% Author Michael Beham
%img = double(img);
%templateimg = double(templateimg);


uavg = mean(mean(templateimg))

sum = zeros(size(img,1), size(img,2));
ss = size(templateimg,1);
st = size(templateimg,2);

for y = 1 : (size(img,2)-st)
    for x = 1 : (size(img,1)-ss)
        zaehler = 0.0;
        nenner1 = 0.0;
        nenner2 = 0.0;
                
        favg = mean(mean(img(x:(x+ss), y:(y+st))));
        for s = 1 : ss
            for t = 1 : st
               %zaehler = zaehler + ( (img(x+s,y+t)-favg)*(templateimg(s,t)-uavg));
               zaehler = zaehler + ( (img(x+s,y+t)-favg)*(templateimg(s,t)-uavg));
               nenner1 = nenner1 + ((img(x+s,y+t)-favg)^2);
               nenner2 = nenner2 + (templateimg(s,t)-uavg)^2;
            end
        end
        
        sum(x,y) = double(zaehler)/sqrt(double(nenner1*nenner2));
    end
    y = y;
end

end